#include "data.h"

#include <string.h>
#include <stdio.h>

// 6 for full marks
int checkChangeCell(){
  int score = 0;
  int width = 50;
  int height = 50;
  char *cells = createNewGrid(50, 50);
  if(changeCell(cells, -1, 1, '0') == 1)
    score++;
  if(changeCell(cells, 1, -1, '0') == 1)
    score++;
  if(changeCell(cells, 51, 1, '0') == 1)
    score++;
  if(changeCell(cells, 1, 51, '0') == 1)
    score++;
  if(changeCell(cells, 1, 1, '2') == 1)
    score++;
  if(score == 5)
    printf("Check function changeCell(invalid input): passed\n");
  else
    printf("Check function changeCell(invalid input): failed\n");
  if(changeCell(cells, 1, 1, '1') == 0 && cells[51] == '1')
    {
      score++;
      printf("Check function changeCell: passed\n");
    }
  else
    printf("Check function changeCell: failed\n");
  printf("score: %d\n", score);
  return score;
}

//4 for full marks
int checkCreateNewGrid(){
  int score1 = 0;
  if(!createNewGrid(0, 1))
    score1++;
  if(!createNewGrid(1, 0))
    score1++;
  if(score1 == 2)
    printf("Check function createNewGrid(invalid input): passed\n");
  else
    printf("Check function createNewGrid(invalid input): failed\n");
  int score2 = 0;
  char *cell1 = createNewGrid(1, 1);
  char *cell2 = createNewGrid(2, 2);
  if(strlen(cell1) == 1 && cell1[0] == '0')
    score2++;
  if(strlen(cell2) == 4 && cell2[0] == '0' && cell2[1] == '0' && cell2[2] == '0' && cell2[3] == '0')
    score2++;
  if(score2 == 2)
    printf("Check function createNewGrid: passed\n");
  else
    printf("Check function createNewGrid: failed\n");
  printf("score: %d\n", score1+score2);
  return score1+score2;
}

//3 for full marks
int checkCount(){
  int score = 0;

  char *cell = createNewGrid(3, 3);
  changeCell(cell, 1, 0, '1');
  changeCell(cell, 1, 2, '1');
  changeCell(cell, 0, 0, '1');
  if(count(cell, 1, 1) == 3)
    score++;
  if(count(cell, 0, 1) == 3)
    score++;
  changeCell(cell, 2, 0, '1');
  if(count(cell, 1, 0) == 2)
    score++;
  if(score == 3)
    printf("Check function count: passed\n");
  else
    printf("Check function count: failed\n");
  printf("score: %d\n", score);
  return score;
}

//5 for full marks
int checkChangeGrid(){
  int score = 0;

  char *cell = createNewGrid(3, 3);
  changeCell(cell, 1, 1, '1');
  if(changeGrid(cell)[4] == '0')
    score++;

  changeCell(cell, 1, 0, '1');
  if(changeGrid(cell)[1] == '0')
    score++;

  changeCell(cell, 1, 2, '1');
  if(changeGrid(cell)[4] == '1')
    score++;

  changeCell(cell, 2, 1, '1');
  changeCell(cell, 2, 2, '1');
  if(changeGrid(cell)[4] == '0')
    score++;

  changeCell(cell, 1, 1, '0');
  changeCell(cell, 2, 2, '0');
  if(changeGrid(cell)[4] == '1')
    score++;

  if(score == 5)
    printf("Check function changeGrid: passed\n");
  else
    printf("Check function changeGrid: failed\n");
  printf("score: %d\n", score);
  return score;
}

int main(){
  int scores = 0;
  scores = checkChangeCell();
  scores += checkCreateNewGrid();
  scores += checkCount();
  scores += checkChangeGrid();

  if(scores == 18)
    printf("All passed\n");
  printf("scores: %d\n", scores);

  char close;
  scanf("%c", &close);
  return 0;
}
